package cn.kill.orderservice.config;

import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.domain.AlipayTradeWapPayModel;
import com.alipay.api.request.AlipayTradeWapPayRequest;
import com.alipay.api.response.AlipayTradeWapPayResponse;

/**
 * @author 张在成
 */
public class AlipayConfig {
	// 超时时间 可空
	public  static String timeout_express="2m";
	/**
	 * 销售产品码 必填
	 */
	public  static String product_code="QUICK_WAP_WAY";
	/**
	 * 应用归属的商户uid
	 */
	public  static  String  BUSUID="2088102179879020";
	// 应用appid.这里模拟使用沙箱账号
	public static String APPID = "2016101600702280";
	/**
	 * 私钥 pkcs8格式的
	 */
	public static String RSA_PRIVATE_KEY = "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC7l9Z26iXg1k9c0xFLmfUP8vbGojVw5WuZ1Lg3E3ZbLUOrKwewlOwA/w9kWccy9wjX0ZzdZSXXV9wSZIZkRUuQG2EbQ1eSrzlRJvekyDDIBu+mwBe3ME98IEiobN2jNtJI3Wz9uKoOKDS8uVW+KemCa63XyVt0ln5ALokqMsL+7/06isaaAnWQyrY0uP0ECHQNYVjFLKvWlP0FiAsVX1Ru1xFVG2nXP5EqfJFKN/2mSB94mMW7N/gFcZj9qCXyeBywVuMzgtXs2dT1sGGyK0NESBQBsAFfoqK7Ix5iyHEaBTz2Ctn0gU5VyvnH88CFhYOv67iVqGJo+OhHp7H3xaD5AgMBAAECggEAOBpg+Y9tZKCze39kXMfekraHN0Cr2ufCFm+X6GDZtMsEwdxMoHLpYiLl540yFfvrmSAHWe82MgEEwDtwNezDfIWztQOe3S+qZKrSxWVZsXjhk20/qnm4S9cb48MrRfTPTxtpzTe9JB7CJu8GxaijPW4Wv8Jop6WafHdubkBgMP3xPWiHrUmqU9YnwOXXKBD/yKm3D6STfSzh2lKJpbaYV3CNjPdTT2oRMHHmpqRy3L/VL2Wp9kfEFY1wpm0WeeZqJqXJOClG3i00J57mbq06mJKPzILzmdfF5rdFdS1JlVjtNMwCJzfJjyBQK/e2wpE2wLR56GFeL0wHayiiGvVRQQKBgQD1uUMSGRQuuEZD91l0m4sU2eGmWgls7R/NTcmLNqMc+g+xRkuAhuaKaNdVfEZuQ5YTd8mtmAntNim03YacHic1r1JY8ucCN/3IR7ZQnmUQUg93Ho2Bn9ugRJDSY8aJXu8MUFpfBhP1yAP5zhdgtaxj353SUyfXFbPTKjYmkjtmDwKBgQDDcDmjFRRrqKecx4pEueKf28/y3vgnsTzGTEVyzjkAuqu5iJVku5aq4Ii4PqXJDFoKjOR/N6Mk95gO6nPqtGH8W7c4JnQiL3o3dRgvaTL0za/UsmgWdxznUMh4+R7CtP5VP5ZEWHV8aHM1UHv/wYiLn0Gj2Gb2hesiL9VDdfPQdwKBgQCn8zqOkimjTTxplBTGiNHlLI743q12kBSehL5usqeGVLyJFFziulG05LfZrBmPoA5hvAxS5IpUYiLbhlZNOqbeILkOJugSMib5z1ojfD/jidMcPfvGT3cT8glyY9P9bK/DIODD9imKYm2lPmHoLgRoNx1t9nxSnHjOqhlc/7ItrQKBgDN3GBZz9J6tGQZWHXkfoigKkGYahSqep6xoZVloKOaiQZpn9z9BjtmMqzQpeyrIT+W7WGiP1Cxl7urunnvN6Ie19zeYGLjv27VC5o2FnF+O0qCmInbYAwp+4WvJ3mnTk64LQpzY1odeUghWG3EsG7L4yyZEVEjS1yp3gidzpjLdAoGBAKpkN3eFT154UY7HRtaS0BomBR4jk8jjXdWfSb5FpBYzR5lPyM84iz+Nk0r2HbH3blJ+sI06WMN+XQeMOjuIT59sRZ2apyqZuazTk9Ipt/M48j5EfDhDbNOBGBRFNQFc8Xd0SwBoOXhvRf7vwnvaFoEsC6/E3pvtfQJcfv0NGKc5";

	/**
	 * 	服务器异步通知页面路径 需http://或者https://格式的完整路径，不能加?id=123这类自定义参数，必须外网可以正常访问
	 */
	public static String notify_url = "http://41o0561m25.wicp.vip/api/alipay/async";

	/**
	 * 	页面跳转同步通知页面路径 需http://或者https://格式的完整路径，不能加?
	 * 	id=123这类自定义参数，必须外网可以正常访问 商户可以自定义同步跳转地址
	 */
	public static String return_url = "http://41o0561m25.wicp.vip/api/alipay/sync";

	/**
	 * 请求网关地址
	 */
	public static String URL = "https://openapi.alipaydev.com/gateway.do";
	/**
	 * 编码
	 */
	public static String CHARSET = "UTF-8";

	/**
	 * 返回格式
	 */
	public static String FORMAT = "json";
	/**
	 * 支付宝公钥
	 */
	public static String ALIPAY_PUBLIC_KEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmx0oloPu9WTosnaf/pmIOAvWRc+6cTHO1A8xl1NVnKdXZ2XqNdqKjCrn32CXr0lWqCsVFHFNJY7s8Jo90Jy8JNJiajAGOYZSW3wNn0IYYte2/ZVHkCO+VRpZj+9H6Md/tc0Eo6e+I7s+8x4tAyCzGW3D1RloRNnxYJ0pQ9U7Fvoks93xs+I48J6QvWN77JRafvfboo4t4yNDT1F/TIFlEhGvUTc27oM2a098wMszq1WyC84nu5cYtn0tOI86cxbxmpyY5FWZG1cCEBEz2EOtnceWmQXFKhJKuAXc1JKvHT/SQGzl0k5QAnGaGu7mZAQZrCKb7VZNj8r/sytxCRdZ2QIDAQAB";
	/**
	 * 日志记录目录
	 */
	public static String log_path = "D:\\alipay\\logs";
	/**
	 * RSA2
	 */
	public static String SIGNTYPE = "RSA2";

	/**
	 * 获取请求下单的链接
	 * @param orderNo
	 * @param money
	 * @param body
	 * @return
	 * @throws AlipayApiException
	 */
	public  static  String  nativePay(String orderNo,String money,String body) throws AlipayApiException {

		// SDK 公共请求类，包含公共请求参数，以及封装了签名与验签，开发者无需关注签名与验签
		//调用RSA签名方式
		AlipayClient client = new DefaultAlipayClient(AlipayConfig.URL, AlipayConfig.APPID, AlipayConfig.RSA_PRIVATE_KEY, AlipayConfig.FORMAT, AlipayConfig.CHARSET, AlipayConfig.ALIPAY_PUBLIC_KEY,AlipayConfig.SIGNTYPE);
		AlipayTradeWapPayRequest alipay_request=new AlipayTradeWapPayRequest();
		// 封装请求支付信息
//		AlipayTradeWapPayModel model=new AlipayTradeWapPayModel();
//		model.setOutTradeNo(orderNo);
//		model.setSubject(body);
//		model.setTotalAmount(money);
//		model.setBody(status);
//		model.setTimeoutExpress(timeout_express);
//		model.setProductCode(product_code);

		JSONObject bizContent = new JSONObject();
		bizContent.put("out_trade_no",orderNo);
		bizContent.put("total_amount",money);
		bizContent.put("subject",body);
		bizContent.put("qr_code_timeout_express", "10m");
		bizContent.put("product_code",AlipayConfig.product_code);

//		alipay_request.setBizModel(model);
		// 设置异步通知地址
		alipay_request.setNotifyUrl(AlipayConfig.notify_url);
		// 设置同步地址
		alipay_request.setReturnUrl(AlipayConfig.return_url);

		alipay_request.setBizContent(bizContent.toString());

		String payResponse = client.pageExecute(alipay_request).getBody();

		System.out.println(payResponse);

		return  payResponse;
	}

}